package com.zyh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zyh.entity.Pet;
import com.zyh.mapper.PetMapper;
import com.zyh.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class PetServiceImpl implements PetService {
    @Autowired
    private PetMapper mapper;

    @Override
    public void insert(Pet pet) {
        mapper.insert(pet);
    }

    @Override
    public void deleteById(Integer id) {
        mapper.deleteById(id);
    }

    @Override
    public void deleteMany(int[] ids) {
        mapper.deleteMany(ids);
    }

    @Override
    public void update(Pet pet) {
        mapper.update(pet);
    }

    @Override
    public Pet selectById(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public List<Pet> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public PageInfo<Pet> selectByPage(Integer pageNum, Integer pageSize) {
//        1,声明开始分页
        PageHelper.startPage(pageNum,pageSize);
//        2,调用mapper的查询所有
        List<Pet> pets = mapper.selectAll();
//        3,创建PageInfo对象
        PageInfo<Pet> pageInfo = new PageInfo<>(pets);
        return pageInfo;
    }
}
